#!/bin/bash
## see http://www.graphviz.org/doc/info/command.html
## added dmalloc to /private/etc/bashrc with function dmalloc { eval `/usr/local/bin/dmalloc -b $*`; }

B="-->"
exec_filename="test_nymrl"

echo "$B compiling admin program..."
echo "$B don't forget to add the -static flag on Linux!!!"
cd ../
AD=" -Wall   -I/usr/local/include     "
LIB=" -Wall  -L/usr/local/lib  -lsqlite3 -lcurl -ldmalloc "

rm -f $exec_filename 
rm -f *.o

gcc -c test.c $AD
gcc -c nymrl.c $AD
gcc -c nymrl_sqlite.c $AD
gcc -c nymrl_conf.c $AD
gcc -c nymrl_log.c $AD
gcc -c nymrl_helper.c $AD
gcc -c sqlite_helper.c $AD
gcc -c lib/cutest/CuTest.c $AD

gcc -c nymrl_message.c $AD
gcc -ggdb -DDMALLOC -DMallocHelp -DDMALLOC_FUNC_CHECK -DNDEBUG -DDEBUG \
     CuTest.o nymrl_conf.o nymrl_helper.o sqlite_helper.o nymrl_message.o nymrl_log.o nymrl_sqlite.o nymrl.o  test.o  \
    -o $exec_filename  $LIB
echo "$B setting up dmalloc logfile"
dmalloc -l logfile -i 1 high
echo "$B running tests"
#./$exec_filename 
echo "$B running GDB" 
echo "you may need to add the following commands to load in shared libraries"
echo "(gdb) sharedlibrary"
echo "(gdb) add-shared-symbol-files"
echo "(gdb) run"
echo "then you can use (gdb) x 0x10234d or info line *(0x82cc) to find memory leaks"
echo " more documentation at http://dmalloc.com/docs "
echo " gdb docs at http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html and http://www.cs.cmu.edu/~gilpin/tutorial/"
gdb --readnow ./$exec_filename 


##gcc -c lib/json_check/json_checker.c $AD
# -ljson
# json_checker.o
# -I/usr/local/include/json/


